import Vue from "vue";
import VueRouter from "vue-router";
import UserLayout from "../layouts/UserLayout.vue";
import BasicLayout from "../layouts/BasicLayout.vue";
import NProgress from "nprogress";
import "nprogress/nprogress.css";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/user",
  },
  {
    path: "/user",
    // component: () => import(/* webpackChunkName: "component" */ "../components/RenderRouterView.vue"),
    //component: { render: h => h("router-view"), },
    component: UserLayout,
    redirect: "/user/login",
    children: [
      {
        path: "/user/login",
        name: "Login",
        component: () =>
          import(/* webpackChunkName: "user" */ "../views/user/login.vue"),
      },
      {
        path: "/user/register",
        name: "Register",
        component: () =>
          import(/* webpackChunkName: "user" */ "../views/user/register.vue"),
      },
    ],
  },
  {
    path: "/main",
    component: BasicLayout,
    name: "主页面布局",
    redirect: "/dashboard/workbench",
    children: [
      {
        path: "/main/dashboard",
        name: "仪表盘",
        icon: "dashboard",
        component: { render: (h) => h("router-view") },
        children: [
          {
            path: "/dashboard/analysis",
            name: "分析页",
            component: () =>
              import(
                /* webpackChunkName: "Dashboard" */ "../views/dashboard/Analysis.vue"
              ),
          },
          {
            path: "/dashboard/monitor",
            name: "监控页",
            component: () =>
              import(
                /* webpackChunkName: "Dashboard" */ "../views/dashboard/Monitor.vue"
              ),
          },
          {
            path: "/dashboard/workbench",
            name: "工作台",
            component: () =>
              import(
                /* webpackChunkName: "Dashboard" */ "../views/dashboard/Workbench.vue"
              ),
          },
        ],
      },
      {
        path: "/main/form",
        component: { render: (h) => h("router-view") },
        name: "表单页",
        icon: "form",
        children: [
          {
            path: "/form/basics",
            name: "基础表单",
            component: () =>
              import(/* webpackChunkName: "Form" */ "../views/form/Basics.vue"),
          },
          {
            path: "/form/distribution",
            name: "分步表单",
            component: () =>
              import(
                /* webpackChunkName: "Form" */ "../views/form/Distribution.vue"
              ),
          },
          {
            path: "/form/senior",
            name: "高级表单",
            component: () =>
              import(/* webpackChunkName: "Form" */ "../views/form/Senior.vue"),
          },
        ],
      },
      {
        path: "/main/list",
        component: { render: (h) => h("router-view") },
        name: "列表页",
        icon: "unordered-list",
        children: [
          {
            path: "/list/query_table",
            name: "查询表格",
            component: () =>
              import(
                /* webpackChunkName: "List" */ "../views/list/QueryTable.vue"
              ),
          },
          {
            path: "/list/standard",
            name: "标准列表",
            component: () =>
              import(
                /* webpackChunkName: "List" */ "../views/list/Standard.vue"
              ),
          },
          {
            path: "/list/card",
            name: "卡片列表",
            component: () =>
              import(/* webpackChunkName: "List" */ "../views/list/Card.vue"),
          },
          {
            path: "/list/search",
            name: "搜索列表",
            component: { render: (h) => h("router-view") },
            children: [
              {
                path: "/list/search/article",
                name: "搜索列表(文章)",
                component: () =>
                  import(
                    /* webpackChunkName: "List/search" */ "../views/list/search/article.vue"
                  ),
              },
              {
                path: "/list/search/project",
                name: "搜索列表(项目)",
                component: () =>
                  import(
                    /* webpackChunkName: "List/search" */ "../views/list/search/project.vue"
                  ),
              },
              {
                path: "/list/search/application",
                name: "搜索列表(应用)",
                component: () =>
                  import(
                    /* webpackChunkName: "List/search" */ "../views/list/search/application.vue"
                  ),
              },
            ],
          },
        ],
      },
      {
        path: "/main/detail",
        component: { render: (h) => h("router-view") },
        name: "详情页",
        icon: "copy",
        children: [
          {
            path: "/detail/basics",
            name: "基础详情页",
            component: () =>
              import(
                /* webpackChunkName: "Detail" */ "../views/detail/Basics.vue"
              ),
          },
          {
            path: "/detail/senior",
            name: "高级详情页",
            component: () =>
              import(
                /* webpackChunkName: "Detail" */ "../views/detail/Senior.vue"
              ),
          },
        ],
      },
      {
        path: "/main/result",
        component: { render: (h) => h("router-view") },
        name: "结果页",
        icon: "issues-close",
        children: [
          {
            path: "/result/success",
            name: "成功页",
            component: () =>
              import(
                /* webpackChunkName: "Result" */ "../views/result/Success.vue"
              ),
          },
          {
            path: "/result/fail",
            name: "失败页",
            component: () =>
              import(
                /* webpackChunkName: "Result" */ "../views/result/Fail.vue"
              ),
          },
        ],
      },
      {
        path: "/main/abnormal",
        component: { render: (h) => h("router-view") },
        name: "异常页",
        icon: "warning",
        children: [
          {
            path: "/abnormal/basics",
            name: "403",
            component: () =>
              import(
                /* webpackChunkName: "abnormal" */ "../views/abnormal/403.vue"
              ),
          },
          {
            path: "/abnormal/distribution",
            name: "404",
            component: () =>
              import(
                /* webpackChunkName: "abnormal" */ "../views/abnormal/404.vue"
              ),
          },
          {
            path: "/abnormal/senior",
            name: "500",
            component: () =>
              import(
                /* webpackChunkName: "abnormal" */ "../views/abnormal/500.vue"
              ),
          },
        ],
      },
      {
        path: "/main/personal",
        component: { render: (h) => h("router-view") },
        name: "个人页",
        icon: "skin",
        children: [
          {
            path: "/personal/center",
            name: "个人中心",
            component: () =>
              import(
                /* webpackChunkName: "Personal" */ "../views/personal/Center.vue"
              ),
          },
          {
            path: "/personal/setting",
            name: "个人设置",
            component: () =>
              import(
                /* webpackChunkName: "Personal" */ "../views/personal/Setting.vue"
              ),
          },
        ],
      },
      {
        path: "/main/android",
        component: () => import("../views/android/index.vue"),
        name: "Android",
        icon: "android",
      },
    ],
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach((to, from, next) => {
  if (to != from) {
    NProgress.start();
    next();
  }
});
router.afterEach((to, from) => {
  console.log(`${to}   ${from}`);
  NProgress.done();
});

export default router;
